// pages/components/footerShopCart/index.js
// const computedBehavior = require('miniprogram-computed')

Component({
  /**
   * 组件的属性列表
   */
  // behaviors: [computedBehavior],
  properties: {
    list:{
      type:Array,
      observer:function(newVal,oldVal,change){
        console.log(newVal, oldVal, change)
        let count=0,money=0
        if(this.properties.list.length>0){
          this.properties.list.forEach((i,index)=>{
            count+=i.num
            money+=(i.money*i.num)
          })
          this.setData({
            count,
            money
          })
        }
      }
    }
  },
  
  /**
   * 组件的初始数据
   */
  data: {
    isShow:false,
    count:0,
    money:0
  },
  /**
   * 组件的方法列表
   */
  methods: {
    //点击--去结算
    goJiesuan(){
      this.triggerEvent('goJiesuan')
    },
    //关闭/打开 弹框
    changeShow(event){
      var dataset=event.currentTarget.dataset
      this.setData({
        isShow:dataset.val
      })
    },
    touchOnGoods(event){
      //加入购物车或移除
      console.log(event.currentTarget.dataset.item)
      this.triggerEvent('touchOnGoods',event)
    },
    clearShopCar(){
      //清空
      this.triggerEvent('clearShopCar')
      this.setData({
        isShow:false
      })
    }
  }
})
